#ifndef RS232_H
#define RS232_H

#include <sys/time.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
  
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
    
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>  
#include <termios.h>

#include <fcntl.h>


//#include "IO.h"

/*Description

RS232 wrapper class; TS7260
*/


/* baudrate settings are defined in <asm/termbits.h>, which is
included by <termios.h> */
#define BAUDRATE B115200
      

#define COM2 "/dev/ttyAM1"
#define COM3 "/dev/ttyAM2"      
/* change this definition for the correct port */
//  #define MODEMDEVICE "/dev/ttyS1"
//  #define _POSIX_SOURCE 1 /* POSIX compliant source */

extern bool verbose_log; //verbose log of process() loops

class RS232
{
        public:
                RS232(char *com);
                ~RS232();
                
                int sendData(unsigned char *buffer, int len);
                unsigned char* getData(unsigned char* &buffer, int &len);
                
                void process();
                void ping();
        private:
                char *COM_STR;
                
                int    fd1;//, fd2;  /* input sources 1 and 2 */
                fd_set readfs;    /* file descriptor set */
                
                struct termios oldtio,newtio;
                
                int res;
                unsigned char buf[255];
                
                void loghex(char *what, unsigned char *buffer, int length);
                void handle_input1();

};

#endif
